<?php


abstract class BaseFood extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $title;


	
	protected $title_lcase;


	
	protected $image_id;


	
	protected $user_id;


	
	protected $quantity;


	
	protected $quantity_type;


	
	protected $quantity_size;


	
	protected $is_liquid = false;


	
	protected $kj;


	
	protected $protein;


	
	protected $fat_total;


	
	protected $fat_saturated;


	
	protected $carbs;


	
	protected $carbs_sugars;


	
	protected $fibre;


	
	protected $sodium;


	
	protected $created_at;


	
	protected $updated_at;

	
	protected $aImage;

	
	protected $aUser;

	
	protected $collFoodDiaryEntrys;

	
	protected $lastFoodDiaryEntryCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getTitle()
	{

		return $this->title;
	}

	
	public function getTitleLcase()
	{

		return $this->title_lcase;
	}

	
	public function getImageId()
	{

		return $this->image_id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getQuantity()
	{

		return $this->quantity;
	}

	
	public function getQuantityType()
	{

		return $this->quantity_type;
	}

	
	public function getQuantitySize()
	{

		return $this->quantity_size;
	}

	
	public function getIsLiquid()
	{

		return $this->is_liquid;
	}

	
	public function getKj()
	{

		return $this->kj;
	}

	
	public function getProtein()
	{

		return $this->protein;
	}

	
	public function getFatTotal()
	{

		return $this->fat_total;
	}

	
	public function getFatSaturated()
	{

		return $this->fat_saturated;
	}

	
	public function getCarbs()
	{

		return $this->carbs;
	}

	
	public function getCarbsSugars()
	{

		return $this->carbs_sugars;
	}

	
	public function getFibre()
	{

		return $this->fibre;
	}

	
	public function getSodium()
	{

		return $this->sodium;
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = FoodPeer::ID;
		}

	} 
	
	public function setTitle($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->title !== $v) {
			$this->title = $v;
			$this->modifiedColumns[] = FoodPeer::TITLE;
		}

	} 
	
	public function setTitleLcase($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->title_lcase !== $v) {
			$this->title_lcase = $v;
			$this->modifiedColumns[] = FoodPeer::TITLE_LCASE;
		}

	} 
	
	public function setImageId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->image_id !== $v) {
			$this->image_id = $v;
			$this->modifiedColumns[] = FoodPeer::IMAGE_ID;
		}

		if ($this->aImage !== null && $this->aImage->getId() !== $v) {
			$this->aImage = null;
		}

	} 
	
	public function setUserId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = FoodPeer::USER_ID;
		}

		if ($this->aUser !== null && $this->aUser->getId() !== $v) {
			$this->aUser = null;
		}

	} 
	
	public function setQuantity($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->quantity !== $v) {
			$this->quantity = $v;
			$this->modifiedColumns[] = FoodPeer::QUANTITY;
		}

	} 
	
	public function setQuantityType($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->quantity_type !== $v) {
			$this->quantity_type = $v;
			$this->modifiedColumns[] = FoodPeer::QUANTITY_TYPE;
		}

	} 
	
	public function setQuantitySize($v)
	{

		if ($this->quantity_size !== $v) {
			$this->quantity_size = $v;
			$this->modifiedColumns[] = FoodPeer::QUANTITY_SIZE;
		}

	} 
	
	public function setIsLiquid($v)
	{

		if ($this->is_liquid !== $v || $v === false) {
			$this->is_liquid = $v;
			$this->modifiedColumns[] = FoodPeer::IS_LIQUID;
		}

	} 
	
	public function setKj($v)
	{

		if ($this->kj !== $v) {
			$this->kj = $v;
			$this->modifiedColumns[] = FoodPeer::KJ;
		}

	} 
	
	public function setProtein($v)
	{

		if ($this->protein !== $v) {
			$this->protein = $v;
			$this->modifiedColumns[] = FoodPeer::PROTEIN;
		}

	} 
	
	public function setFatTotal($v)
	{

		if ($this->fat_total !== $v) {
			$this->fat_total = $v;
			$this->modifiedColumns[] = FoodPeer::FAT_TOTAL;
		}

	} 
	
	public function setFatSaturated($v)
	{

		if ($this->fat_saturated !== $v) {
			$this->fat_saturated = $v;
			$this->modifiedColumns[] = FoodPeer::FAT_SATURATED;
		}

	} 
	
	public function setCarbs($v)
	{

		if ($this->carbs !== $v) {
			$this->carbs = $v;
			$this->modifiedColumns[] = FoodPeer::CARBS;
		}

	} 
	
	public function setCarbsSugars($v)
	{

		if ($this->carbs_sugars !== $v) {
			$this->carbs_sugars = $v;
			$this->modifiedColumns[] = FoodPeer::CARBS_SUGARS;
		}

	} 
	
	public function setFibre($v)
	{

		if ($this->fibre !== $v) {
			$this->fibre = $v;
			$this->modifiedColumns[] = FoodPeer::FIBRE;
		}

	} 
	
	public function setSodium($v)
	{

		if ($this->sodium !== $v) {
			$this->sodium = $v;
			$this->modifiedColumns[] = FoodPeer::SODIUM;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = FoodPeer::CREATED_AT;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = FoodPeer::UPDATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->title = $rs->getString($startcol + 1);

			$this->title_lcase = $rs->getString($startcol + 2);

			$this->image_id = $rs->getInt($startcol + 3);

			$this->user_id = $rs->getInt($startcol + 4);

			$this->quantity = $rs->getInt($startcol + 5);

			$this->quantity_type = $rs->getString($startcol + 6);

			$this->quantity_size = $rs->getFloat($startcol + 7);

			$this->is_liquid = $rs->getBoolean($startcol + 8);

			$this->kj = $rs->getFloat($startcol + 9);

			$this->protein = $rs->getFloat($startcol + 10);

			$this->fat_total = $rs->getFloat($startcol + 11);

			$this->fat_saturated = $rs->getFloat($startcol + 12);

			$this->carbs = $rs->getFloat($startcol + 13);

			$this->carbs_sugars = $rs->getFloat($startcol + 14);

			$this->fibre = $rs->getFloat($startcol + 15);

			$this->sodium = $rs->getFloat($startcol + 16);

			$this->created_at = $rs->getTimestamp($startcol + 17, null);

			$this->updated_at = $rs->getTimestamp($startcol + 18, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 19; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Food object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FoodPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			FoodPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isNew() && !$this->isColumnModified(FoodPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

    if ($this->isModified() && !$this->isColumnModified(FoodPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FoodPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aImage !== null) {
				if ($this->aImage->isModified()) {
					$affectedRows += $this->aImage->save($con);
				}
				$this->setImage($this->aImage);
			}

			if ($this->aUser !== null) {
				if ($this->aUser->isModified()) {
					$affectedRows += $this->aUser->save($con);
				}
				$this->setUser($this->aUser);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = FoodPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += FoodPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collFoodDiaryEntrys !== null) {
				foreach($this->collFoodDiaryEntrys as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aImage !== null) {
				if (!$this->aImage->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aImage->getValidationFailures());
				}
			}

			if ($this->aUser !== null) {
				if (!$this->aUser->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
				}
			}


			if (($retval = FoodPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collFoodDiaryEntrys !== null) {
					foreach($this->collFoodDiaryEntrys as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FoodPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getTitle();
				break;
			case 2:
				return $this->getTitleLcase();
				break;
			case 3:
				return $this->getImageId();
				break;
			case 4:
				return $this->getUserId();
				break;
			case 5:
				return $this->getQuantity();
				break;
			case 6:
				return $this->getQuantityType();
				break;
			case 7:
				return $this->getQuantitySize();
				break;
			case 8:
				return $this->getIsLiquid();
				break;
			case 9:
				return $this->getKj();
				break;
			case 10:
				return $this->getProtein();
				break;
			case 11:
				return $this->getFatTotal();
				break;
			case 12:
				return $this->getFatSaturated();
				break;
			case 13:
				return $this->getCarbs();
				break;
			case 14:
				return $this->getCarbsSugars();
				break;
			case 15:
				return $this->getFibre();
				break;
			case 16:
				return $this->getSodium();
				break;
			case 17:
				return $this->getCreatedAt();
				break;
			case 18:
				return $this->getUpdatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FoodPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getTitle(),
			$keys[2] => $this->getTitleLcase(),
			$keys[3] => $this->getImageId(),
			$keys[4] => $this->getUserId(),
			$keys[5] => $this->getQuantity(),
			$keys[6] => $this->getQuantityType(),
			$keys[7] => $this->getQuantitySize(),
			$keys[8] => $this->getIsLiquid(),
			$keys[9] => $this->getKj(),
			$keys[10] => $this->getProtein(),
			$keys[11] => $this->getFatTotal(),
			$keys[12] => $this->getFatSaturated(),
			$keys[13] => $this->getCarbs(),
			$keys[14] => $this->getCarbsSugars(),
			$keys[15] => $this->getFibre(),
			$keys[16] => $this->getSodium(),
			$keys[17] => $this->getCreatedAt(),
			$keys[18] => $this->getUpdatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FoodPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setTitle($value);
				break;
			case 2:
				$this->setTitleLcase($value);
				break;
			case 3:
				$this->setImageId($value);
				break;
			case 4:
				$this->setUserId($value);
				break;
			case 5:
				$this->setQuantity($value);
				break;
			case 6:
				$this->setQuantityType($value);
				break;
			case 7:
				$this->setQuantitySize($value);
				break;
			case 8:
				$this->setIsLiquid($value);
				break;
			case 9:
				$this->setKj($value);
				break;
			case 10:
				$this->setProtein($value);
				break;
			case 11:
				$this->setFatTotal($value);
				break;
			case 12:
				$this->setFatSaturated($value);
				break;
			case 13:
				$this->setCarbs($value);
				break;
			case 14:
				$this->setCarbsSugars($value);
				break;
			case 15:
				$this->setFibre($value);
				break;
			case 16:
				$this->setSodium($value);
				break;
			case 17:
				$this->setCreatedAt($value);
				break;
			case 18:
				$this->setUpdatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FoodPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setTitle($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setTitleLcase($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setImageId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setUserId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setQuantity($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setQuantityType($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setQuantitySize($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setIsLiquid($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setKj($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setProtein($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setFatTotal($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setFatSaturated($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setCarbs($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setCarbsSugars($arr[$keys[14]]);
		if (array_key_exists($keys[15], $arr)) $this->setFibre($arr[$keys[15]]);
		if (array_key_exists($keys[16], $arr)) $this->setSodium($arr[$keys[16]]);
		if (array_key_exists($keys[17], $arr)) $this->setCreatedAt($arr[$keys[17]]);
		if (array_key_exists($keys[18], $arr)) $this->setUpdatedAt($arr[$keys[18]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(FoodPeer::DATABASE_NAME);

		if ($this->isColumnModified(FoodPeer::ID)) $criteria->add(FoodPeer::ID, $this->id);
		if ($this->isColumnModified(FoodPeer::TITLE)) $criteria->add(FoodPeer::TITLE, $this->title);
		if ($this->isColumnModified(FoodPeer::TITLE_LCASE)) $criteria->add(FoodPeer::TITLE_LCASE, $this->title_lcase);
		if ($this->isColumnModified(FoodPeer::IMAGE_ID)) $criteria->add(FoodPeer::IMAGE_ID, $this->image_id);
		if ($this->isColumnModified(FoodPeer::USER_ID)) $criteria->add(FoodPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(FoodPeer::QUANTITY)) $criteria->add(FoodPeer::QUANTITY, $this->quantity);
		if ($this->isColumnModified(FoodPeer::QUANTITY_TYPE)) $criteria->add(FoodPeer::QUANTITY_TYPE, $this->quantity_type);
		if ($this->isColumnModified(FoodPeer::QUANTITY_SIZE)) $criteria->add(FoodPeer::QUANTITY_SIZE, $this->quantity_size);
		if ($this->isColumnModified(FoodPeer::IS_LIQUID)) $criteria->add(FoodPeer::IS_LIQUID, $this->is_liquid);
		if ($this->isColumnModified(FoodPeer::KJ)) $criteria->add(FoodPeer::KJ, $this->kj);
		if ($this->isColumnModified(FoodPeer::PROTEIN)) $criteria->add(FoodPeer::PROTEIN, $this->protein);
		if ($this->isColumnModified(FoodPeer::FAT_TOTAL)) $criteria->add(FoodPeer::FAT_TOTAL, $this->fat_total);
		if ($this->isColumnModified(FoodPeer::FAT_SATURATED)) $criteria->add(FoodPeer::FAT_SATURATED, $this->fat_saturated);
		if ($this->isColumnModified(FoodPeer::CARBS)) $criteria->add(FoodPeer::CARBS, $this->carbs);
		if ($this->isColumnModified(FoodPeer::CARBS_SUGARS)) $criteria->add(FoodPeer::CARBS_SUGARS, $this->carbs_sugars);
		if ($this->isColumnModified(FoodPeer::FIBRE)) $criteria->add(FoodPeer::FIBRE, $this->fibre);
		if ($this->isColumnModified(FoodPeer::SODIUM)) $criteria->add(FoodPeer::SODIUM, $this->sodium);
		if ($this->isColumnModified(FoodPeer::CREATED_AT)) $criteria->add(FoodPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(FoodPeer::UPDATED_AT)) $criteria->add(FoodPeer::UPDATED_AT, $this->updated_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(FoodPeer::DATABASE_NAME);

		$criteria->add(FoodPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setTitle($this->title);

		$copyObj->setTitleLcase($this->title_lcase);

		$copyObj->setImageId($this->image_id);

		$copyObj->setUserId($this->user_id);

		$copyObj->setQuantity($this->quantity);

		$copyObj->setQuantityType($this->quantity_type);

		$copyObj->setQuantitySize($this->quantity_size);

		$copyObj->setIsLiquid($this->is_liquid);

		$copyObj->setKj($this->kj);

		$copyObj->setProtein($this->protein);

		$copyObj->setFatTotal($this->fat_total);

		$copyObj->setFatSaturated($this->fat_saturated);

		$copyObj->setCarbs($this->carbs);

		$copyObj->setCarbsSugars($this->carbs_sugars);

		$copyObj->setFibre($this->fibre);

		$copyObj->setSodium($this->sodium);

		$copyObj->setCreatedAt($this->created_at);

		$copyObj->setUpdatedAt($this->updated_at);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getFoodDiaryEntrys() as $relObj) {
				$copyObj->addFoodDiaryEntry($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new FoodPeer();
		}
		return self::$peer;
	}

	
	public function setImage($v)
	{


		if ($v === null) {
			$this->setImageId(NULL);
		} else {
			$this->setImageId($v->getId());
		}


		$this->aImage = $v;
	}


	
	public function getImage($con = null)
	{
		if ($this->aImage === null && ($this->image_id !== null)) {
						include_once 'lib/model/om/BaseImagePeer.php';

			$this->aImage = ImagePeer::retrieveByPK($this->image_id, $con);

			
		}
		return $this->aImage;
	}

	
	public function setUser($v)
	{


		if ($v === null) {
			$this->setUserId(NULL);
		} else {
			$this->setUserId($v->getId());
		}


		$this->aUser = $v;
	}


	
	public function getUser($con = null)
	{
		if ($this->aUser === null && ($this->user_id !== null)) {
						include_once 'lib/model/om/BaseUserPeer.php';

			$this->aUser = UserPeer::retrieveByPK($this->user_id, $con);

			
		}
		return $this->aUser;
	}

	
	public function initFoodDiaryEntrys()
	{
		if ($this->collFoodDiaryEntrys === null) {
			$this->collFoodDiaryEntrys = array();
		}
	}

	
	public function getFoodDiaryEntrys($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFoodDiaryEntryPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFoodDiaryEntrys === null) {
			if ($this->isNew()) {
			   $this->collFoodDiaryEntrys = array();
			} else {

				$criteria->add(FoodDiaryEntryPeer::FOOD_ID, $this->getId());

				FoodDiaryEntryPeer::addSelectColumns($criteria);
				$this->collFoodDiaryEntrys = FoodDiaryEntryPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(FoodDiaryEntryPeer::FOOD_ID, $this->getId());

				FoodDiaryEntryPeer::addSelectColumns($criteria);
				if (!isset($this->lastFoodDiaryEntryCriteria) || !$this->lastFoodDiaryEntryCriteria->equals($criteria)) {
					$this->collFoodDiaryEntrys = FoodDiaryEntryPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastFoodDiaryEntryCriteria = $criteria;
		return $this->collFoodDiaryEntrys;
	}

	
	public function countFoodDiaryEntrys($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseFoodDiaryEntryPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(FoodDiaryEntryPeer::FOOD_ID, $this->getId());

		return FoodDiaryEntryPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addFoodDiaryEntry(FoodDiaryEntry $l)
	{
		$this->collFoodDiaryEntrys[] = $l;
		$l->setFood($this);
	}


	
	public function getFoodDiaryEntrysJoinUser($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFoodDiaryEntryPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFoodDiaryEntrys === null) {
			if ($this->isNew()) {
				$this->collFoodDiaryEntrys = array();
			} else {

				$criteria->add(FoodDiaryEntryPeer::FOOD_ID, $this->getId());

				$this->collFoodDiaryEntrys = FoodDiaryEntryPeer::doSelectJoinUser($criteria, $con);
			}
		} else {
									
			$criteria->add(FoodDiaryEntryPeer::FOOD_ID, $this->getId());

			if (!isset($this->lastFoodDiaryEntryCriteria) || !$this->lastFoodDiaryEntryCriteria->equals($criteria)) {
				$this->collFoodDiaryEntrys = FoodDiaryEntryPeer::doSelectJoinUser($criteria, $con);
			}
		}
		$this->lastFoodDiaryEntryCriteria = $criteria;

		return $this->collFoodDiaryEntrys;
	}

} 